package com.lz.reference;

/**
 * PointOrValueDemo..       java中只有值因引用
 *
 * @author Lizhong
 * @date 2019/4/3
 */
class A {
    int i;
}

public class PointOrValueDemo {
    public static void main(String[] args) {
        A a1 = new A();
        a1.i = 5;
        swap(a1);
        System.out.println(a1.i); // 2
        A a2 = a1;
        swap2(a1);                // 3
        System.out.println(a1 + "=" + a2); //==
        System.out.println(a1.i + "=" + a2.i);//==
        swap3(a2);
        System.out.println(a2.i);   //3
        System.out.println(a1.i + "=" + a2.i);//==

    }

    private static void swap(A a1) {
        a1.i = 2;
    }

    private static void swap2(A a1) {
        a1.i = 3;

    }    private static void swap3(A a1) {
       a1=new A();
       a1.i=-1;
    }

}
